package it.apiconsulting.sharem.controller;

import it.apiconsulting.sharem.dao.BranoDao;
import it.apiconsulting.sharem.dao.PlaylistDao;
import it.apiconsulting.sharem.model.Brano;
import it.apiconsulting.sharem.model.Playlist;

import java.util.List;


public class PlaylistAction extends BaseAction {

	private static final long serialVersionUID = 9149826260758390091L;
	
	private String nome;
	private String path;
	private String fileName;
	private Playlist playlist;
	private List<Playlist> playlists;
	private PlaylistDao linkPlaylistController;
	
	private BranoDao linkBranoController;
	
	private String id;

	public PlaylistAction() {
		super();
		linkPlaylistController = new PlaylistDao();
		linkBranoController = new BranoDao();
	}

	public String execute() {
		if ( isLocalLogged() ){
			return SUCCESS;
		} else return LOGIN;	
	}

	public String save() throws Exception {
		
		if ( isLocalLogged() ){
			
			Playlist obj = new Playlist();
//			obj.setIdUser(getFactory().getInstance().getUtente().getId());
			obj.setPath(getPath());
			obj.setNome(getNome());
			obj.setDurata("");
			obj.setStato(false);
			linkPlaylistController.add(obj);
			
            Brano brano = new Brano();
            brano.setArtista("");
            brano.setDurata("");
            brano.setGenere("");
            brano.setIdPlaylist(obj.getId());
            brano.setTitolo("");
            brano.setPath(getFileName());
            linkBranoController.add(brano);
            
	        return SUCCESS;
		} else return LOGIN;	
	}

	public String delete() {
		if ( isLocalLogged() ) return SUCCESS;
		else return LOGIN;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public Playlist getPlaylist() {
		return playlist;
	}

	public void setPlaylist(Playlist playlist) {
		this.playlist = playlist;
	}

	public List<Playlist> getPlaylists() {
		return playlists;
	}

	public void setPlaylists(List<Playlist> playlists) {
		this.playlists = playlists;
	}
	
	public String getNome() {
		return nome;
	}

	public void setNome(String nome) {
		this.nome = nome;
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}
}